package com.product;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.ProductDao;
import com.vo.Product;

public class ProductListServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		int epc_id = 0;
		if(request.getParameter("epc_id") != null){
			epc_id = Integer.parseInt(request.getParameter("epc_id"));
		}
		ProductDao dao = new ProductDao();
		List<Product> list = new ArrayList<Product>();
		Product product = null;
		try {
			list = dao.getAllDate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(int a=0;a<list.size();a++){
			if(epc_id == list.get(a).getEpc_id()){
				product = list.get(a);
				System.out.println(product.getDiscount()+"2:"+product.getEp_price()+"3"+product.getNow_price());
			}
		}
		HttpSession session = request.getSession();
		session.setAttribute("productList", product);
		request.getRequestDispatcher("product-list.jsp").forward(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

}
